home *** CD-ROM | disk | FTP | other *** search
- /* ------------------------------------------------------------------------------
-
- FILENAME
- Utilities.c
-
- DESCRIPTION
- This file contains the utility routines (e.g. string manipulation routines)
- which are used by the other modules within the Additions printing extension.
-
-
- COPYRIGHT
- Copyright Apple Computer, Inc. 1991
- All rights reserved.
-
- INTERFACE ROUTINES
- GetCopiesFromJob
- MinNum
- StrCopyMax
- StrConcat
- CheckBoxIsOn
- EnableControlOnOff
-
- MODIFICATION HISTORY
- 05/15/91 ALA Initial Implementation
-
-
- ------------------------------------------------------------------------------- */
-
- #include <Types.h>
- #include <Quickdraw.h>
- #include <Memory.h>
- #include <Resources.h>
- #include <Dialogs.h>
- #include <TextEdit.h>
- #include <OSUtils.h>
- #include <Packages.h>
- #include <ToolUtils.h>
- #include <Menus.h>
- #include <String.h>
- #include <Strings.h>
- #include <Printing.h>
-
- #include <graphics routines.h>
- #include <graphics libraries.h>
- #include <Font Library.h>
-
- #include <Collections.h>
- #include <Messages.h>
-
- #include <PrintingManager.h>
- #include <PrintingMessages.h>
-
-
- /*==================================== INTERFACE ROUTINES ====================================*/
-
-
- /* ===== GetCopiesFromJob =====
-
- Returns the number of copies specified in the job record; 1 if the record cannot be accessed.
- */
- long GetCopiesFromJob( // (out) Number of copies in the job record
- Collection jobCollection) // (in) Documents job record
- {
- gxCopiesInfo copiesInfo;
-
- copiesInfo.copies = 1;
-
- /* Try and get the print dialog info. */
-
- GetCollectionItem (jobCollection,
- gxCopiesTag,
- gxPrintingTagID,
- nil,
- &copiesInfo);
-
- return(copiesInfo.copies);
- }
- /* GetCopiesFromJob */
-
-
- /* ===== MinNum =====
-
- Returns the minimum of 'long1' and 'long2'.
- */
- long MinNum( // (out) the minimum of long1 and long2
- long long1, // (in) the first long to consider
- long long2) // (in) the second long to consider
- {
- return( ((long1) < (long2)) ? (long1) : (long2) );
- }
- /* MinNum */
-
-
- /* ===== StrCopyMax =====
-
- Copies the contents of 'srcStr' to 'dstStr', but copies no more than maxToCopy characters
- (not including the terminating '\0').
-
- Returns 'dstStr'.
- */
- char *StrCopyMax( // (out) pointer to 'dstStr'
- const char *srcStr, // (in) pointer to the string to copy (C string)
- char *dstStr, // (in) pointer to the string to receive the copy (C string)
- long maxToCopy) // (in) maximum number of characters to copy
- {
- char *saveStr;
- long i;
- long sLen;
-
- saveStr = dstStr;
- sLen = MinNum( strlen(srcStr), maxToCopy );
-
- for ( i = 1; i <= sLen; i++ )
- *(dstStr++) = *(srcStr++);
-
- *dstStr = '\0';
-
- return( saveStr );
- }
- /* StrCopyMax */
-
-
- /* ===== StrConcat =====
-
- Concatenates 'str2' to the end of 'str1' (it is assumed that 'str1'
- can expand by strlen('str2') characters).
-
- Returns 'str1'.
- */
- char *StrConcat( // (out) pointer to 'str1' with 'str2' concatenated
- char *str1, // (in) pointer to the string to concatenate to (C string)
- const char *str2) // (in) pointer to the string to concatenate (C string)
- {
- /* copy string2 to the end of string1 (including the trailing '\0') */
- BlockMove( str2, (str1 + strlen(str1)), strlen(str2) + 1 );
-
- return( str1 );
- }
- /* StrConcat */
-
-
- /* ===== CheckBoxIsOn =====
-
- CheckBoxIsOn turns true if a dialog checkbox button is checked; false otherwise.
- */
- Boolean CheckBoxIsOn( // (out) Returns true if button is checked; false otherwise
- DialogPtr pDlg, // (in) target dialog
- short whichItem) // (in) dialog item to be changed
- {
- ControlHandle theChkBox;
- short itemType;
- Rect itemRect;
-
- GetDItem(pDlg, whichItem, &itemType, (Handle *) &theChkBox, &itemRect);
-
- return( GetCtlValue(theChkBox) == 1 );
- }
- /* CheckBoxIsOn */
-
-
- /* ===== EnableControlOnOff =====
-
- EnableControlOnOff enables or disables the specified radio button.
- */
- void EnableControlOnOff(
- DialogPtr pDlg, // (in) target dialog
- short whichItem, // (in) dialog item to be changed
- Boolean enableIt) // (in) T => enable the item; F => disable it
- {
- short itemType;
- Rect itemRect;
- Handle hItem;
-
- GetDItem(pDlg, whichItem, &itemType, &hItem, &itemRect);
- HiliteControl((ControlHandle) hItem, (enableIt) ? 0 : 255);
- }
- /* EnableControlOnOff */
-
-
-